/**
 * Create at 2006-5-12 10:30:25
 */
package com.hengpeng.common.web.tags;

import java.io.IOException;

import javax.servlet.Servlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @author linriqing
 */
/**
 * <pre>
 * 子框架窗口标签, ,纠正了非根目录使用"/"的路径错误问题
 * </pre>
 * @author linriqing
 * @version 1.0, 2006-6-16
 */
public class IFrameTag extends BodyTagSupport
{
	private static Log logger = LogFactory.getLog(IFrameTag.class);

	private static final long serialVersionUID = 9191619856483424054L;

	private String frameborder;

	private String id;

	private String src;

	private String style;

	public IFrameTag()
	{
		super();
	}

	public int doEndTag() throws JspException
	{
		return super.doEndTag();
	}

	public int doStartTag() throws JspException
	{
		super.doStartTag();
		try
		{
			StringBuffer sb = new StringBuffer();
			sb.append("<IFrame ");
			if (this.id != null)
			{
				sb.append("id=\"" + this.id + "\" ");
			}
			if (this.src != null)
			{
				if (this.src.startsWith("/"))
				{
					HttpServletRequest req = (HttpServletRequest) this.pageContext.getRequest();
					this.src = req.getContextPath() + this.src;
				}
				sb.append("src=\"" + this.src + "\" ");
			}
			if (this.frameborder != null)
			{
				sb.append("frameborder=\"" + this.frameborder + "\" ");
			}
			if (this.style != null)
			{
				sb.append("style=\"" + this.style + "\" ");
			}
			sb.append("></IFrame>");
			this.pageContext.getOut().print(sb.toString());
		}
		catch (IOException e)
		{
			logger.error("do IFrameTag failed, page:" + ((Servlet) this.pageContext.getPage()).toString()
					+ ", falt detail:" + e.toString());
		}
		return SKIP_BODY;
	}

	/**
	 * @return frameborder.
	 */
	public String getFrameborder()
	{
		return frameborder;
	}

	/**
	 * @return id.
	 */
	public String getId()
	{
		return id;
	}

	/**
	 * @return src.
	 */
	public String getSrc()
	{
		return src;
	}

	/**
	 * @return style.
	 */
	public String getStyle()
	{
		return style;
	}

	/**
	 * @param frameborder frameborder
	 */
	public void setFrameborder(String frameborder)
	{
		this.frameborder = frameborder;
	}

	/**
	 * @param id id
	 */
	public void setId(String id)
	{
		this.id = id;
	}

	/**
	 * @param src src
	 */
	public void setSrc(String src)
	{
		this.src = src;
	}

	/**
	 * @param style style
	 */
	public void setStyle(String style)
	{
		this.style = style;
	}

}
